package com.abvnet.project.water.sewage.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.sewage.domain.SewageFlow;
import com.abvnet.project.water.sewage.service.ISewageFlowService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程处理单元信息操作处理
 * 
 * @author duj
 * @date 2019-07-19
 */
@Controller
@RequestMapping("/sewage/sewageFlow")
public class SewageFlowController extends BaseController {
    private String prefix = "sewage/sewageFlow";
	
	@Autowired
	private ISewageFlowService sewageFlowService;
	
	@RequiresPermissions("sewage:sewageFlow:list")
	@GetMapping()
	public String sewageFlow()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询流程处理单元列表
	 */
	@RequiresPermissions("sewage:sewageFlow:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SewageFlow sewageFlow) {
		startPage();
        List<SewageFlow> list = sewageFlowService.selectSewageFlowList(sewageFlow);
		return getDataTable(list);
	}
	
	/**
	 * 新增流程处理单元
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存流程处理单元
	 */
	@RequiresPermissions("sewage:sewageFlow:add")
	@Log(title = "流程处理单元", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SewageFlow sewageFlow) {
		return toAjax(sewageFlowService.insertSewageFlow(sewageFlow));
	}

	/**
	 * 修改流程处理单元
	 */
	@GetMapping("/edit/{flowId}")
	public String edit(@PathVariable("flowId") Integer flowId, ModelMap mmap) {
		SewageFlow sewageFlow = sewageFlowService.selectSewageFlowById(flowId);
		mmap.put("sewageFlow", sewageFlow);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存流程处理单元
	 */
	@RequiresPermissions("sewage:sewageFlow:edit")
	@Log(title = "流程处理单元", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SewageFlow sewageFlow) {
		return toAjax(sewageFlowService.updateSewageFlow(sewageFlow));
	}
	
	/**
	 * 删除流程处理单元
	 */
	@RequiresPermissions("sewage:sewageFlow:remove")
	@Log(title = "流程处理单元", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sewageFlowService.deleteSewageFlowByIds(ids));
	}
	
}
